/*
 * Copyright (C) 2017 Pingan, Inc. All Rights Reserved.
 */

package com.pingan.haofang.searchcloud.es.schema.type;

import com.pingan.haofang.searchcloud.api.matedata.constant.MetadataFieldType;

import java.util.HashMap;
import java.util.Map;

/**
 * 类型映射
 *
 * @author zhangbi617
 * @date 2017-07-13
 */
public class MetaFieldTypeMapper {

    public static final String TYPE_INT = "integer";
    public static final String TYPE_LONG = "long";
    public static final String TYPE_FLOAT = "float";
    public static final String TYPE_DOUBLE = "double";

    public static final String TYPE_KEYWORD = "keyword";
    public static final String TYPE_TEXT = "text";
    public static final String TYPE_GEO_POINT = "geo_point";

    private static final Map<String, String> MAPPER = new HashMap<>();

    static {
        MAPPER.put(MetadataFieldType.INT.getFieldType(), TYPE_INT);
        MAPPER.put(MetadataFieldType.STRING.getFieldType(), TYPE_KEYWORD);
        MAPPER.put(MetadataFieldType.TEXT_LIKE.getFieldType(), TYPE_KEYWORD);
        MAPPER.put(MetadataFieldType.MY_IK.getFieldType(), TYPE_TEXT);
        MAPPER.put(MetadataFieldType.GEO.getFieldType(), TYPE_GEO_POINT);
    }

    /**
     * 获取ES数据类型
     *
     * @param metaFieldType
     * @return
     */
    public static String getEsType(String metaFieldType) {
        return MAPPER.getOrDefault(metaFieldType, metaFieldType);
    }

}
